package com.example.permissionsystem1_1.businessFunction.controller.converter;

import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.roleFunctionReqDto.RoleFunctionSelectAllFunctionsByRoleIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.roleFunctionReqDto.RoleFunctionSetRoleFunctionRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.userRoleReqDto.UserRoleSelectAllRolesByUserIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.userRoleReqDto.UserRoleSetUserRoleRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.roleFunctionRspDto.RoleFunctionRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.roleFunctionRspDto.RoleFunctionSelectAllFunctionsByRoleIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.roleFunctionRspDto.RoleFunctionSetRoleFunctionRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleSelectAllRolesByUserIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleSetUserRoleRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.roleFunctionReqModel.RoleFunctionSelectAllFunctionsByRoleIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.roleFunctionReqModel.RoleFunctionSetRoleFunctionRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSelectAllRolesByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSetUserRoleRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionSelectAllFunctionsByRoleIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionSetRoleFunctionRelationRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSelectAllRolesByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSetUserRoleRelationRspModel;
import com.example.permissionsystem1_1.common.businessFunction.BaseControllerConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class RoleFunctionControllerConverter extends BaseControllerConverter {
    //1.根据用户id查询全部角色信息
    public static RoleFunctionSelectAllFunctionsByRoleIdReqModel convertDtoToModel(RoleFunctionSelectAllFunctionsByRoleIdReqDto reqDto) {
        if(reqDto==null || reqDto.getRoleId()==null){
            return null;
        }
        RoleFunctionSelectAllFunctionsByRoleIdReqModel reqModel=new RoleFunctionSelectAllFunctionsByRoleIdReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static RoleFunctionSelectAllFunctionsByRoleIdRspDto convertModelToDto(RoleFunctionSelectAllFunctionsByRoleIdRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        RoleFunctionSelectAllFunctionsByRoleIdRspDto rspDto=new RoleFunctionSelectAllFunctionsByRoleIdRspDto();
        if(rspModel.getRoleFunctionRspModels()!=null&&rspModel.getRoleFunctionRspModels().size()>0){
            List<RoleFunctionRspDto> roleFunctionRspDtos=new ArrayList<>();
            List<RoleFunctionRspModel> roleFunctionRspModels=rspModel.getRoleFunctionRspModels();
            for (RoleFunctionRspModel roleFunctionRspModel:roleFunctionRspModels) {
                RoleFunctionRspDto roleFunctionRspDto=new RoleFunctionRspDto();
                BeanUtils.copyProperties(roleFunctionRspModel, roleFunctionRspDto);
                roleFunctionRspDtos.add(roleFunctionRspDto);
            }
            rspDto.setRoleFunctionRspDtos(roleFunctionRspDtos);
        }
        return rspDto;
    }
    //2.设置用户与角色的关联关系
    public static RoleFunctionSetRoleFunctionRelationReqModel convertDtoToModel(RoleFunctionSetRoleFunctionRelationReqDto reqDto) {
        if(reqDto==null || reqDto.getRoleId()==null || reqDto.getFunctionIds()==null || reqDto.getFunctionIds().size()<=0){
            return null;
        }
        RoleFunctionSetRoleFunctionRelationReqModel reqModel=new RoleFunctionSetRoleFunctionRelationReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static RoleFunctionSetRoleFunctionRelationRspDto convertModelToDto(RoleFunctionSetRoleFunctionRelationRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        RoleFunctionSetRoleFunctionRelationRspDto rspDto=new RoleFunctionSetRoleFunctionRelationRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }


}
